package SolveQuestions;

import java.io.Console;
import java.security.KeyStore;
import java.util.*;

public class l347 {

    class Solution{
        public int[] topKFrequent(int[] nums, int k) {
            HashMap<Integer, Integer> record = new HashMap<>();
            for(int val: nums){
                if(record.containsKey(val)){
                    record.replace(val, record.get(val) + 1);
                }else{
                    record.put(val, 1);
                }
            }

            ArrayList<Map.Entry<Integer, Integer>> arr = new ArrayList<>(record.entrySet());
            Collections.sort(arr, (o1, o2) -> o2.getValue() - o1.getValue());
            int[] result = new int[k];
            for(int i = 0; i < k; i ++) {
                result[i] = arr.get(i).getKey();
            }
            return result;
        }
    }

    public static void main(String[] args) {
        l347 temp = new l347();
        Solution a = temp.new Solution();
        Scanner input = new Scanner(System.in);
        int k = input.nextInt();
        int[] nums = new int[1000];
        int count = 0;
        while(input.hasNext()){
            nums[count++] = input.nextInt();
        }
        int[] b = a.topKFrequent(nums, k);
        for(int val: b){
            System.out.printf("%d ", val);
        }
    }

}


